package main;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

import control.Button;
import control.ControlCommand;

public class SellectGameCanvas extends GameCanvas {
	protected Button[] listButton;
	protected final MainMidlet game;
	//protected Image background;

	protected SellectGameCanvas(MainMidlet midlet) {
		super(true);
		this.game = midlet;
		setFullScreenMode(true);

		int sW = getWidth();
		int bW = 155;
		listButton = new Button[4];

		listButton[0] = new Button(Res.IMG_BUTTON, bW, 40, (sW - bW) / 2, 220,
				"TUTORIAL");
		listButton[0].setCommand(new ControlCommand() {
			public void Do() {
				
				PlayingCanvas.getInstance().setTutorial();
				game.showPlayingCanvas();
				//PlayingCanvas.getInstance().start();
			}
		});

		listButton[1] = new Button(Res.IMG_BUTTON, bW, 40, (sW - bW) / 2, 100,
				"NEW GAME");
		listButton[1].setCommand(new ControlCommand() {
			public void Do() {
				
				PlayingCanvas.getInstance().resetGame();
				game.showPlayingCanvas();
			}
		});

		listButton[2] = new Button(Res.IMG_BUTTON, bW, 40, (sW - bW) / 2, 140,
				"CONTINUES");
		listButton[2].setCommand(new ControlCommand() {
			public void Do() {
				
				PlayingCanvas.getInstance().loadGame();
				game.showPlayingCanvas();
			}
		});
		
		listButton[3] = new Button(Res.IMG_BUTTON, bW, 40, (sW - bW) / 2, 260,
				"MAIN MENU");
		listButton[3].setCommand(new ControlCommand() {
			public void Do() {
				game.showMenuCanvas();
			}
		});
		
	}
	
	public void update(){
		listButton[2].setEnable(PlayingCanvas.getInstance().existingSavedGame());
	}

	protected void pointerPressed(int x, int y) {
		for (int i = 0; i < listButton.length; i++) {
			listButton[i].pointerPressed(x, y);
		}
		repaint();
	}

	protected void pointerReleased(int x, int y) {
		for (int i = 0; i < listButton.length; i++) {
			listButton[i].pointerReleased(x, y);
		}
		repaint();
	}

	protected void pointerDragged(int x, int y) {
		for (int i = 0; i < listButton.length; i++) {
			listButton[i].pointerPressed(x, y);
		}
		repaint();
	}

	public void paint(Graphics g) {
		g.setColor(0x886600);
		g.fillRect(0, 0, 240, 400);
		for (int i = 0; i < listButton.length; i++) {
			listButton[i].paint(g);
		}
	}
}
